package com.hut.oa.model.dao.user;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.hut.oa.model.bean.Dept;

public interface DeptDao extends PagingAndSortingRepository<Dept, Long>{
	Page<Dept> findAll(Pageable pageable);//分页查询所有

	@Query("from Dept d where d.name like %:key% or d.tel like %:key% or d.email like %:key%")
	Page<Dept> findByNameLOrTelOrEmail(@Param("key")String key,Pageable pageable);//模糊查询部门信息
	
	List<Dept> findAllByOrderByGrade();//按层级排序获取全部
	
	Dept findById(Long id);//根据id获取
	
	@Query("update Dept d set d.grade=:grade where d.id=:id")
	@Modifying
	int updateGrade(@Param("grade")Integer grade,@Param("id")Long id);//修改层级

}
